/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DataPenyewa.java
 *
 * Created on Nov 18, 2011, 4:12:44 PM
 */
package DataPenyewa;

import DBKoneksi.TestConection;
import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Piyo
 */
public class DataPenyewaPanel extends javax.swing.JPanel {

    /** Creates new form DataPenyewa */
    public DataPenyewaPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        JudulLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        IDLabel = new javax.swing.JLabel();
        NOIDLabel = new javax.swing.JLabel();
        NamaLabel = new javax.swing.JLabel();
        AlamatLabel = new javax.swing.JLabel();
        NoTelpLabel = new javax.swing.JLabel();
        SubmitButton = new javax.swing.JButton();
        IDTF = new javax.swing.JTextField();
        NoTF = new javax.swing.JTextField();
        NamaTF = new javax.swing.JTextField();
        AlamatTF = new javax.swing.JTextField();
        TlpnTF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        jDesktopPane1.setBackground(new java.awt.Color(255, 255, 255));

        JudulLabel.setFont(new java.awt.Font("Georgia", 1, 14));
        JudulLabel.setForeground(new java.awt.Color(51, 102, 0));
        JudulLabel.setText("Form Data Penyewa");
        JudulLabel.setBounds(120, 10, 150, 30);
        jDesktopPane1.add(JudulLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(0, 50, 400, 10);
        jDesktopPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IDLabel.setText("ID Penyewa");
        IDLabel.setBounds(10, 70, 170, 30);
        jDesktopPane1.add(IDLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NOIDLabel.setText("No. Identitas");
        NOIDLabel.setBounds(10, 110, 170, 30);
        jDesktopPane1.add(NOIDLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NamaLabel.setText("Nama Penyewa");
        NamaLabel.setBounds(10, 150, 150, 30);
        jDesktopPane1.add(NamaLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AlamatLabel.setText("Alamat Penyewa");
        AlamatLabel.setBounds(10, 190, 160, 30);
        jDesktopPane1.add(AlamatLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        NoTelpLabel.setText("No Telepon");
        NoTelpLabel.setBounds(10, 230, 170, 30);
        jDesktopPane1.add(NoTelpLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SubmitButton.setText("Submit");
        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitButtonActionPerformed(evt);
            }
        });
        SubmitButton.setBounds(150, 280, 90, 30);
        jDesktopPane1.add(SubmitButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IDTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IDTFActionPerformed(evt);
            }
        });
        IDTF.setBounds(150, 70, 240, 30);
        jDesktopPane1.add(IDTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        NoTF.setBounds(150, 110, 240, 30);
        jDesktopPane1.add(NoTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        NamaTF.setBounds(150, 150, 240, 30);
        jDesktopPane1.add(NamaTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        AlamatTF.setBounds(150, 190, 240, 30);
        jDesktopPane1.add(AlamatTF, javax.swing.JLayeredPane.DEFAULT_LAYER);
        TlpnTF.setBounds(150, 230, 240, 30);
        jDesktopPane1.add(TlpnTF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DataPenyewa/green wallpaper.jpg"))); // NOI18N
        jLabel1.setText("jLabel1");
        jLabel1.setBounds(0, 0, 400, 330);
        jDesktopPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

private void IDTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IDTFActionPerformed
// TODO add your handling code here:
//    buatnomor();
}//GEN-LAST:event_IDTFActionPerformed
    public void bersih() {
        IDTF.setText("");
        NoTF.setText("");
        NamaTF.setText("");
        AlamatTF.setText("");
        TlpnTF.setText("");
    }
private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonActionPerformed
// TODO add your handling code here:
    try {
        TestConection connec = new TestConection();
        Statement statement = connec.getConnection().createStatement();

        String sql = "insert into DATAPENYEWA values ('" + IDTF.getText()
                + "', '" + NoTF.getText() + "' , '"
                + NamaTF.getText() + "', '"
                + AlamatTF.getText() + "' , '" + TlpnTF.getText() + "')";
        int result = statement.executeUpdate(sql);

//connec.close();
        JOptionPane.showMessageDialog(null, "Data berhasil di simpan");
        bersih();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Proses penyimpanan gagal/koneksi gagal");
        System.out.println(e.getMessage());
        bersih();
    }
}//GEN-LAST:event_SubmitButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AlamatLabel;
    private javax.swing.JTextField AlamatTF;
    private javax.swing.JLabel IDLabel;
    private javax.swing.JTextField IDTF;
    private javax.swing.JLabel JudulLabel;
    private javax.swing.JLabel NOIDLabel;
    private javax.swing.JLabel NamaLabel;
    private javax.swing.JTextField NamaTF;
    private javax.swing.JTextField NoTF;
    private javax.swing.JLabel NoTelpLabel;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JTextField TlpnTF;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
